// pages/contacts/list.js
var api = require('../../utils/api.js');
var util = require('../../utils/util.js');
var orgid = "";
Page({

  /**
   * 页面的初始数据
   */
  data: {
    toView: "inToView01",
    searchName: "",
    //字母排序
    orientationList: [{
      Lid: "02",
      letter: "A"
    },
    {
      Lid: "03",
      letter: "B"
    },
    {
      Lid: "04",
      letter: "C"
    },
    {
      Lid: "05",
      letter: "D"
    },
    {
      Lid: "06",
      letter: "E"
    },
    {
      Lid: "07",
      letter: "F"
    },
    {
      Lid: "08",
      letter: "G"
    },
    {
      Lid: "09",
      letter: "H"
    },
    {
      Lid: "10",
      letter: "I"
    },
    {
      Lid: "11",
      letter: "J"
    },
    {
      Lid: "12",
      letter: "K"
    },
    {
      Lid: "13",
      letter: "L"
    },
    {
      Lid: "14",
      letter: "M"
    },
    {
      Lid: "15",
      letter: "N"
    },
    {
      Lid: "16",
      letter: "O"
    },
    {
      Lid: "17",
      letter: "P"
    },
    {
      Lid: "18",
      letter: "Q"
    },
    {
      Lid: "19",
      letter: "R"
    },
    {
      Lid: "20",
      letter: "S"
    },
    {
      Lid: "21",
      letter: "T"
    },
    {
      Lid: "22",
      letter: "U"
    },
    {
      Lid: "23",
      letter: "V"
    },
    {
      Lid: "24",
      letter: "W"
    },
    {
      Lid: "25",
      letter: "X"
    },
    {
      Lid: "26",
      letter: "Y"
    },
    {
      Lid: "27",
      letter: "Z"
    }
    ],
    oldList: [{
      Lid: "02",
      letter: "A",
      count: 0,
      lawyers: []
    },
    {
      Lid: "03",
      letter: "B",
      count: 0,
      lawyers: []
    },
    {
      Lid: "04",
      letter: "C",
      count: 0,
      lawyers: []
    },
    {
      Lid: "05",
      letter: "D",
      count: 0,
      lawyers: []
    },
    {
      Lid: "06",
      letter: "E",
      count: 0,
      lawyers: []
    },
    {
      Lid: "07",
      letter: "F",
      count: 0,
      lawyers: []
    },
    {
      Lid: "08",
      letter: "G",
      count: 0,
      lawyers: []
    },
    {
      Lid: "09",
      letter: "H",
      count: 0,
      lawyers: []
    },
    {
      Lid: "10",
      letter: "I",
      count: 0,
      lawyers: []
    },
    {
      Lid: "11",
      letter: "J",
      count: 0,
      lawyers: []
    },
    {
      Lid: "12",
      letter: "K",
      count: 0,
      lawyers: []
    },
    {
      Lid: "13",
      letter: "L",
      count: 0,
      lawyers: []
    },
    {
      Lid: "14",
      letter: "M",
      count: 0,
      lawyers: []
    },
    {
      Lid: "15",
      letter: "N",
      count: 0,
      lawyers: []
    },
    {
      Lid: "16",
      letter: "O",
      count: 0,
      lawyers: []
    },
    {
      Lid: "17",
      letter: "P",
      count: 0,
      lawyers: []
    },
    {
      Lid: "18",
      letter: "Q",
      count: 0,
      lawyers: []
    },
    {
      Lid: "19",
      letter: "R",
      count: 0,
      lawyers: []
    },
    {
      Lid: "20",
      letter: "S",
      count: 0,
      lawyers: []
    },
    {
      Lid: "21",
      letter: "T",
      count: 0,
      lawyers: []
    },
    {
      Lid: "22",
      letter: "U",
      count: 0,
      lawyers: []
    },
    {
      Lid: "23",
      letter: "V",
      count: 0,
      lawyers: []
    },
    {
      Lid: "24",
      letter: "W",
      count: 0,
      lawyers: []
    },
    {
      Lid: "25",
      letter: "X",
      count: 0,
      lawyers: []
    },
    {
      Lid: "26",
      letter: "Y",
      count: 0,
      lawyers: []
    },
    {
      Lid: "27",
      letter: "Z",
      count: 0,
      lawyers: []
    }
    ],
    //律师通讯录
    lawyerList: [{
      Lid: "02",
      letter: "A",
      count: 0,
      lawyers: []
    },
    {
      Lid: "03",
      letter: "B",
      count: 0,
      lawyers: []
    },
    {
      Lid: "04",
      letter: "C",
      count: 0,
      lawyers: []
    },
    {
      Lid: "05",
      letter: "D",
      count: 0,
      lawyers: []
    },
    {
      Lid: "06",
      letter: "E",
      count: 0,
      lawyers: []
    },
    {
      Lid: "07",
      letter: "F",
      count: 0,
      lawyers: []
    },
    {
      Lid: "08",
      letter: "G",
      count: 0,
      lawyers: []
    },
    {
      Lid: "09",
      letter: "H",
      count: 0,
      lawyers: []
    },
    {
      Lid: "10",
      letter: "I",
      count: 0,
      lawyers: []
    },
    {
      Lid: "11",
      letter: "J",
      count: 0,
      lawyers: []
    },
    {
      Lid: "12",
      letter: "K",
      count: 0,
      lawyers: []
    },
    {
      Lid: "13",
      letter: "L",
      count: 0,
      lawyers: []
    },
    {
      Lid: "14",
      letter: "M",
      count: 0,
      lawyers: []
    },
    {
      Lid: "15",
      letter: "N",
      count: 0,
      lawyers: []
    },
    {
      Lid: "16",
      letter: "O",
      count: 0,
      lawyers: []
    },
    {
      Lid: "17",
      letter: "P",
      count: 0,
      lawyers: []
    },
    {
      Lid: "18",
      letter: "Q",
      count: 0,
      lawyers: []
    },
    {
      Lid: "19",
      letter: "R",
      count: 0,
      lawyers: []
    },
    {
      Lid: "20",
      letter: "S",
      count: 0,
      lawyers: []
    },
    {
      Lid: "21",
      letter: "T",
      count: 0,
      lawyers: []
    },
    {
      Lid: "22",
      letter: "U",
      count: 0,
      lawyers: []
    },
    {
      Lid: "23",
      letter: "V",
      count: 0,
      lawyers: []
    },
    {
      Lid: "24",
      letter: "W",
      count: 0,
      lawyers: []
    },
    {
      Lid: "25",
      letter: "X",
      count: 0,
      lawyers: []
    },
    {
      Lid: "26",
      letter: "Y",
      count: 0,
      lawyers: []
    },
    {
      Lid: "27",
      letter: "Z",
      count: 0,
      lawyers: []
    }]
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    orgid = wx.getStorageSync('companyId');
    this.getlawyerList();
  },
  /**
   * 得到律师详情
   */
  getlawyerList: function () {
    var that = this;
    wx.showLoading({
      title: "正在加载中...",
    })
    var lawyerList = that.data.lawyerList;
    api.fetchApi2("phoneBook/queryBook?orgid=" + orgid + "&searchName=" + that.data.searchName, {
    }, "POST").then(res => {
      wx.hideLoading();
      var datas = res.data.data;
      for (let i = 0; i < datas.length; i++) {
        var nameInitials = datas[i].nameInitials;
        var userName = datas[i].userName;
        var nameInitials = datas[i].nameInitials;
        for (let j = 0; j < lawyerList.length; j++) {
          if (lawyerList[j].letter == nameInitials) {
            lawyerList[j].lawyers.push(datas[i]);
            lawyerList[j].count += 1;
          }
        }
      }
      that.setData({
        lawyerList: lawyerList
      })
    });
  },
  /** 律师通讯录搜索*/
  searchCaseList: function (e) {
    var that = this;
    //重新搜索清空值
    that.setData({
      lawyerList: that.data.oldList,
      searchName: e.detail.value
    })
    that.getlawyerList();
  },
  clearInput: function (e) {
    var that = this;
    that.setData({
      lawyerList: that.data.oldList,
      searchName: "",
    })
    that.getlawyerList();
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  },
  //跳转定位  
  scrollToViewFn: function (e) {
    var idx = e.target.dataset.id;
    this.setData({
      toView: "inToView" + idx
    })
    console.log(this.data.toView);
  },
  pagelawyerTap: function (option) {
    var id = option.currentTarget.dataset.brandid;
    wx.navigateTo({
      url: 'details?lawyerId=' + id
    });
  }
})